package com.atguigu.servicebase.exception;

import com.atguigu.commonutils.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

/**
 * create by: zr
 * description: TODO
 * create time: 2021/11/7 12:39
 * 自定义全局异常类
 *
 * @Param: null
 * @return
 */
@Data
@ApiModel(value = "自定义全局异常类")
public class EduException extends RuntimeException {
    @ApiModelProperty(value = "异常状态码")
    private Integer code;

    /**
     * 通过状态码 和异常错误消息 创建异常对象
     *
     * @param message
     * @param code
     */
    public EduException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 接受枚举类型
     *
     * @param resultCode 结果代码
     */
    public EduException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
    }

    @Override
    public String toString() {
        return "EduException{" +
                "message=" + this.getMessage() +
                ", code=" + code +
                '}';
    }

}
